<?php
include_once ("connect.php");
include_once ("log_order.php"); //test!
$action = $_GET['action'];
switch ($action) {
	case 'edit' : 

		$user_id = htmlspecialchars(stripslashes(trim($_POST['user_id'])));
		
		$idc_name = htmlspecialchars(stripslashes(trim($_POST['idc_name'])));
		$sex = htmlspecialchars(stripslashes(trim($_POST['sex'])));
		$country = htmlspecialchars(stripslashes(trim($_POST['country'])));		
		$province = htmlspecialchars(stripslashes(trim($_POST['province'])));
		$city = htmlspecialchars(stripslashes(trim($_POST['city'])));
		$address = htmlspecialchars(stripslashes(trim($_POST['address'])));
		$postcode = htmlspecialchars(stripslashes(trim($_POST['postcode'])));			
		$tel = htmlspecialchars(stripslashes(trim($_POST['tel'])));
		$qq = htmlspecialchars(stripslashes(trim($_POST['qq'])));
		
		
		$sql = "SELECT id FROM order_user WHERE id=$user_id ";	
		$logger->debug($sql);  //test!
		$result = mysql_query($sql);
		if ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
			$sql = "UPDATE order_user SET idc_name='$idc_name',sex='$sex',country='$country',city='$city',address='$address',postcode='$postcode',tel='$tel',qq='$qq',update_time=now() WHERE id=$user_id";
			mysql_query($sql);
			
		} else {
			$sql = "INSERT INTO order_user(id,idc_name,sex,country,city,address,postcode,tel,qq,update_time) VALUES($user_id,'$idc_name','$sex','$country','$city','$address','$postcode','$tel','$qq',now())";
			$logger->debug($sql);  //test!
			mysql_query($sql);
		}

		$logger->debug("user_id=".$user_id);  //test!
		
		echo $user_id;		
		break;	
	
	case 'ch_pw' :	
	
		//-----------------------------
		//---include 
		require_once( '../wp-load.php' );
		//---get user_id
		global $current_user;
		get_currentuserinfo();
		$user_id = $current_user->ID;
		
		$pass1 = htmlspecialchars(stripslashes(trim($_POST['pass1'])));
	
		$sql = "UPDATE ".$wpdb->users." SET user_pass = '".md5($pass1)."' WHERE id=$user_id";
		$logger->debug($sql);  //test!
		mysql_query($sql);
		
		echo 1;
		
		break;	
//----------------------------------------------------------------------------------
	

	case '' :
		echo 'Bad request.';
		break;
}



//------------------



?>